package com.hhs.storage.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.hhs.storage.bean.*;
import com.hhs.storage.service.WorkOvertimeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author chx
 * @since 2024-01-22
 */
@RestController
@RequestMapping("/overtime")
@ApiSupport(order = 1)
@Api(tags = "申请加班")
public class WorkOvertimeController {
    @Resource
    private WorkOvertimeService workOvertimeService;

    @RequestMapping(value = "table")
    @ApiOperation(value = "获取表格数据",
            httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = String.class, name = "page", value = "页码", required =
                    true, paramType = "query"),
            @ApiImplicitParam(dataTypeClass = String.class, name = "size", value = "每页条数", required =
                    true, paramType = "query"),
    })
    @ApiOperationSupport(order = 1)
    public ResponseBeanPage<WorkOvertime> getAll(@ApiIgnore WorkOvertime workOvertime, @ApiIgnore InputParam inputParam) {
        Map<String, Object> map = workOvertimeService.getAll(workOvertime, inputParam);
        ResponseBeanPage res = ResponseBeanPage.getInstance();
        res.setCode((Integer) map.get("code"));
        res.setRows((List) map.get("rows"));
        res.setTotal((Long) map.get("total"));
        return res;
    }

    @PostMapping(value = "add")
    @ApiOperation(value = "添加加班时间",
            httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = String.class, name = "overtimeDate", value = "加班日期", required =
                    true, paramType = "body"),
            @ApiImplicitParam(dataTypeClass = List.class, name = "timeQuantum", value = "加班时间段", required =
                    true, paramType = "body"),
    })
    @ApiOperationSupport(order = 1)
    public ResponseBean<WorkOvertime> add(@ApiIgnore @RequestBody WorkOvertime workOvertime) {
        Map<String, Object> map = workOvertimeService.add(workOvertime);
        ResponseBean res = ResponseBean.getInstance();
        res.setCode((Integer) map.get("code"));
        res.setData(map.get("data"));
        return res;
    }

    @PostMapping(value = "delete")
    @ApiOperation(value = "删除",
            httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = String.class, name = "id", value = "id", required =
                    true, paramType = "query"),
    })
    @ApiOperationSupport(order = 1)
    public ResponseBean<WorkOvertime> delete(String id) {
        Map<String, Object> map = workOvertimeService.delete(id);
        ResponseBean res = ResponseBean.getInstance();
        res.setCode((Integer) map.get("code"));
        res.setData(map.get("data"));
        return res;
    }

    @PostMapping(value = "edit")
    @ApiOperation(value = "编辑",
            httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = String.class, name = "id", value = "id", required =
                    true, paramType = "body"),
            @ApiImplicitParam(dataTypeClass = String.class, name = "overtimeDate", value = "加班日期", required =
                    false, paramType = "body"),
            @ApiImplicitParam(dataTypeClass = List.class, name = "timeQuantum", value = "加班时间段", required =
                    true, paramType = "body"),
    })
    @ApiOperationSupport(order = 1)
    public ResponseBean<WorkOvertime> edit(@ApiIgnore @RequestBody WorkOvertime workOvertime) {
        Map<String, Object> map = workOvertimeService.edit(workOvertime);
        ResponseBean res = ResponseBean.getInstance();
        res.setCode((Integer) map.get("code"));
        res.setData(map.get("data"));
        return res;
    }

    @PostMapping(value = "detail")
    @ApiOperation(value = "详情",
            httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = String.class, name = "id", value = "id", required =
                    true, paramType = "query"),
    })
    @ApiOperationSupport(order = 1)
    public ResponseBean<WorkOvertime> detail(String id){
        Map<String, Object> map = workOvertimeService.detail(id);
        ResponseBean res = ResponseBean.getInstance();
        res.setCode((Integer) map.get("code"));
        res.setData(map.get("data"));
        return res;
    }
}